home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / Snippets / Devices / SCSI Simple Sample / Src / SCSIGetCommandLength.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-24  |  1.3 KB  |  44 lines  |  [TEXT/KAHL]

  1. /*                                SCSIGetCommandLength.c                            */
  2. /*
  3.  * SCSIGetCommandLength.c
  4.  * Copyright © 1992-94 Apple Computer Inc. All Rights Reserved.
  5.  *
  6.  * Use the command byte to determine the length of the SCSI Command. This will
  7.  * work for all registered SCSI-II commands, but not for "vendor-specific"
  8.  * commands, or commands outside of the registered range.  Returns zero
  9.  * for "unknown" or one of the defined command lengths, 6, 10, or 12..
  10.  *
  11.  * Calling Sequence:
  12.  *        unsigned short        SCSIGetCommandLength(
  13.  *                const Ptr        cmdBlock
  14.  *            );
  15.  */
  16. #include "MacSCSICommand.h"
  17. unsigned short                SCSIGetCommandLength(
  18.         const SCSI_CommandPtr    cmdBlock
  19.     );
  20.  
  21. unsigned short
  22. SCSIGetCommandLength(
  23.         const SCSI_CommandPtr    cmdBlock
  24.     )
  25. {
  26.         unsigned short            result;
  27.         /*
  28.          * Look at the "group code" in the command operation. Return a parameter
  29.          * error for the reserved (3, 4) and vendor-specific command (6, 7)
  30.          * command groups. Otherwise, set the command length from the group code
  31.          * value as specified in the SCSI-II spec. Then, copy the command block
  32.          * into the parameter block (this centralizes everything for debugging
  33.          * convenience).
  34.          */
  35.         switch (cmdBlock->scsi[0] & 0xE0) {
  36.         case (0 << 5):    result = 6;        break;
  37.         case (1 << 5):
  38.         case (2 << 5):    result = 10;    break;
  39.         case (5 << 5):    result = 12;    break;
  40.         default:        result = 0;        break;
  41.         }
  42.         return (result);
  43. }
  44.